<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy, BangPatterns #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# OPTIONS_GHC -funbox-strict-fields #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Module      :  GHC.IO.Buffer</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2008</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-10"></span><span class="hs-comment">--</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Portability :  non-portable (GHC Extensions)</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Buffers used in the IO system</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Buffer</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Buffers of any element</span></span><span>
</span><span id="line-21"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier">Buffer</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier">BufferState</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier">CharBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier">CharBufElem</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Creation</span></span><span>
</span><span id="line-24"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier">newByteBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier">newCharBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier">newBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#emptyBuffer"><span class="hs-identifier">emptyBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Insertion/removal</span></span><span>
</span><span id="line-30"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier">bufferRemove</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdd"><span class="hs-identifier">bufferAdd</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#slideContents"><span class="hs-identifier">slideContents</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier">bufferAdjustL</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier">bufferAddOffset</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdjustOffset"><span class="hs-identifier">bufferAdjustOffset</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Inspecting</span></span><span>
</span><span id="line-38"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier">isEmptyBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier">isFullBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#isFullCharBuffer"><span class="hs-identifier">isFullCharBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier">isWriteBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier">bufferElems</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-43"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier">bufferAvailable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-44"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier">bufferOffset</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier">summaryBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Operating on the raw buffer as a Ptr</span></span><span>
</span><span id="line-48"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier">withBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-49"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier">withRawBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Assertions</span></span><span>
</span><span id="line-52"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#checkBuffer"><span class="hs-identifier">checkBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Raw buffers</span></span><span>
</span><span id="line-55"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier">RawBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-56"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#readWord8Buf"><span class="hs-identifier">readWord8Buf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-57"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#writeWord8Buf"><span class="hs-identifier">writeWord8Buf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-58"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier">RawCharBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-59"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier">peekCharBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-60"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier">readCharBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-61"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier">writeCharBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-62"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-identifier">readCharBufPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-63"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBufPtr"><span class="hs-identifier">writeCharBufPtr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-64"></span><span>    </span><span class="annot"><a href="GHC.IO.Buffer.html#charSize"><span class="hs-identifier">charSize</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-65"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-68"></span><span class="hs-comment">-- import GHC.IO</span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Word.html"><span class="hs-identifier">GHC.Word</span></a></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-73"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-74"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>
</span><span id="line-75"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.ForeignPtr.html"><span class="hs-identifier">GHC.ForeignPtr</span></a></span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier">unsafeWithForeignPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>
</span><span id="line-77"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.ForeignPtr.html"><span class="hs-identifier">Foreign.ForeignPtr</span></a></span><span>
</span><span id="line-78"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="hs-comment">-- Char buffers use either UTF-16 or UTF-32, with the endianness matching</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- the endianness of the host.</span><span>
</span><span id="line-82"></span><span class="hs-comment">--</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- Invariants:</span><span>
</span><span id="line-84"></span><span class="hs-comment">--   * a Char buffer consists of *valid* UTF-16 or UTF-32</span><span>
</span><span id="line-85"></span><span class="hs-comment">--   * only whole characters: no partial surrogate pairs</span><span class="hs-cpp">

#define CHARBUF_UTF32
</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- #define CHARBUF_UTF16</span><span>
</span><span id="line-90"></span><span class="hs-comment">--</span><span>
</span><span id="line-91"></span><span class="hs-comment">-- NB. it won't work to just change this to CHARBUF_UTF16.  Some of</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- the code to make this work is there, and it has been tested with</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- the Iconv codec, but there are some pieces that are known to be</span><span>
</span><span id="line-94"></span><span class="hs-comment">-- broken.  In particular, the built-in codecs</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- e.g. GHC.IO.Encoding.UTF{8,16,32} need to use isFullCharBuffer or</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- similar in place of the ow &gt;= os comparisons.</span><span>
</span><span id="line-97"></span><span class="hs-comment">--</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- Tamar: We need to do this eventually for Windows, as we have to re-encode</span><span>
</span><span id="line-99"></span><span class="hs-comment">-- the text as UTF-16 anyway, so if we can avoid it it would be great.</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- Raw blocks of data</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="hs-keyword">type</span><span> </span><span id="RawBuffer"><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-var">RawBuffer</span></a></span></span><span> </span><span id="local-6989586621679534404"><span class="annot"><a href="#local-6989586621679534404"><span class="hs-identifier hs-type">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.ForeignPtr.html#ForeignPtr"><span class="hs-identifier hs-type">ForeignPtr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534404"><span class="hs-identifier hs-type">e</span></a></span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span class="annot"><a href="GHC.IO.Buffer.html#readWord8Buf"><span class="hs-identifier hs-type">readWord8Buf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-107"></span><span id="readWord8Buf"><span class="annot"><span class="annottext">readWord8Buf :: RawBuffer Word8 -&gt; Int -&gt; IO Word8
</span><a href="GHC.IO.Buffer.html#readWord8Buf"><span class="hs-identifier hs-var hs-var">readWord8Buf</span></a></span></span><span> </span><span id="local-6989586621679534403"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534403"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679534402"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534402"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8 -&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier hs-var">unsafeWithForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534403"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO Word8) -&gt; IO Word8)
-&gt; (Ptr Word8 -&gt; IO Word8) -&gt; IO Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534401"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534401"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; IO Word8
forall a b. Storable a =&gt; Ptr b -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekByteOff"><span class="hs-identifier hs-var">peekByteOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534401"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534402"><span class="hs-identifier hs-var">ix</span></a></span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span class="annot"><a href="GHC.IO.Buffer.html#writeWord8Buf"><span class="hs-identifier hs-type">writeWord8Buf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-110"></span><span id="writeWord8Buf"><span class="annot"><span class="annottext">writeWord8Buf :: RawBuffer Word8 -&gt; Int -&gt; Word8 -&gt; IO ()
</span><a href="GHC.IO.Buffer.html#writeWord8Buf"><span class="hs-identifier hs-var hs-var">writeWord8Buf</span></a></span></span><span> </span><span id="local-6989586621679534399"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534399"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679534398"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534398"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span id="local-6989586621679534397"><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679534397"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8 -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier hs-var">unsafeWithForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534399"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534396"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534396"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Word8 -&gt; IO ()
forall a b. Storable a =&gt; Ptr b -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeByteOff"><span class="hs-identifier hs-var">pokeByteOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534396"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534398"><span class="hs-identifier hs-var">ix</span></a></span><span> </span><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679534397"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-cpp">

#if defined(CHARBUF_UTF16)
</span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">CharBufElem</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word16</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">type</span><span> </span><span id="CharBufElem"><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier hs-var">CharBufElem</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-118"></span><span class="hs-keyword">type</span><span> </span><span id="RawCharBuffer"><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-var">RawCharBuffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier hs-type">CharBufElem</span></a></span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="annot"><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier hs-type">peekCharBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-121"></span><span id="peekCharBuf"><span class="annot"><span class="annottext">peekCharBuf :: RawCharBuffer -&gt; Int -&gt; IO Char
</span><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier hs-var hs-var">peekCharBuf</span></a></span></span><span> </span><span id="local-6989586621679534394"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534394"><span class="hs-identifier hs-var">arr</span></a></span></span><span> </span><span id="local-6989586621679534393"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534393"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; (Ptr Char -&gt; IO Char) -&gt; IO Char
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier hs-var">unsafeWithForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534394"><span class="hs-identifier hs-var">arr</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Char -&gt; IO Char) -&gt; IO Char)
-&gt; (Ptr Char -&gt; IO Char) -&gt; IO Char
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534392"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534392"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-122"></span><span>                        </span><span class="hs-special">(</span><span id="local-6989586621679534391"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534391"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-identifier hs-var">readCharBufPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534392"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534393"><span class="hs-identifier hs-var">ix</span></a></span><span>
</span><span id="line-123"></span><span>                        </span><span class="annot"><span class="annottext">Char -&gt; IO Char
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534391"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-pragma hs-type">readCharBuf</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-126"></span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-type">readCharBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-127"></span><span id="readCharBuf"><span class="annot"><span class="annottext">readCharBuf :: RawCharBuffer -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-var hs-var">readCharBuf</span></a></span></span><span> </span><span id="local-6989586621679534390"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534390"><span class="hs-identifier hs-var">arr</span></a></span></span><span> </span><span id="local-6989586621679534389"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534389"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; (Ptr Char -&gt; IO (Char, Int)) -&gt; IO (Char, Int)
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier hs-var">unsafeWithForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534390"><span class="hs-identifier hs-var">arr</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Char -&gt; IO (Char, Int)) -&gt; IO (Char, Int))
-&gt; (Ptr Char -&gt; IO (Char, Int)) -&gt; IO (Char, Int)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534388"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534388"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-identifier hs-var">readCharBufPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534388"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534389"><span class="hs-identifier hs-var">ix</span></a></span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-pragma hs-type">writeCharBuf</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-130"></span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-type">writeCharBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-131"></span><span id="writeCharBuf"><span class="annot"><span class="annottext">writeCharBuf :: RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var hs-var">writeCharBuf</span></a></span></span><span> </span><span id="local-6989586621679534387"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534387"><span class="hs-identifier hs-var">arr</span></a></span></span><span> </span><span id="local-6989586621679534386"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534386"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span id="local-6989586621679534385"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534385"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; (Ptr Char -&gt; IO Int) -&gt; IO Int
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#unsafeWithForeignPtr"><span class="hs-identifier hs-var">unsafeWithForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679534387"><span class="hs-identifier hs-var">arr</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Char -&gt; IO Int) -&gt; IO Int) -&gt; (Ptr Char -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534384"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534384"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBufPtr"><span class="hs-identifier hs-var">writeCharBufPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534384"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534386"><span class="hs-identifier hs-var">ix</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534385"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-pragma hs-type">readCharBufPtr</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-134"></span><span class="annot"><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-identifier hs-type">readCharBufPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier hs-type">CharBufElem</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span class="hs-identifier">readCharBufPtr</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">ix</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-137"></span><span>  </span><span class="hs-identifier">c1</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekElemOff</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">ix</span><span>
</span><span id="line-138"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c1</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0xd800</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-operator">&gt;</span><span> </span><span class="hs-number">0xdbff</span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">chr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c1</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-140"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekElemOff</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-141"></span><span>             </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafeChr</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">0xd800</span><span class="hs-special">)</span><span class="hs-operator">*</span><span class="hs-number">0x400</span><span> </span><span class="hs-operator">+</span><span>
</span><span id="line-142"></span><span>                                </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">0xdc00</span><span class="hs-special">)</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">0x10000</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span id="readCharBufPtr"><span class="annot"><span class="annottext">readCharBufPtr :: Ptr Char -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBufPtr"><span class="hs-identifier hs-var hs-var">readCharBufPtr</span></a></span></span><span> </span><span id="local-6989586621679534383"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534383"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span id="local-6989586621679534382"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534382"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679534381"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534381"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO Char
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Char -&gt; Ptr Char
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534383"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534382"><span class="hs-identifier hs-var">ix</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Char, Int) -&gt; IO (Char, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534381"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534382"><span class="hs-identifier hs-var">ix</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-147"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBufPtr"><span class="hs-pragma hs-type">writeCharBufPtr</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-148"></span><span class="annot"><a href="GHC.IO.Buffer.html#writeCharBufPtr"><span class="hs-identifier hs-type">writeCharBufPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier hs-type">CharBufElem</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span class="hs-identifier">writeCharBufPtr</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">ix</span><span> </span><span class="hs-identifier">ch</span><span>
</span><span id="line-151"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0x10000</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">pokeElemOff</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">ix</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span>
</span><span id="line-152"></span><span>                     </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">c'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">0x10000</span><span>
</span><span id="line-154"></span><span>                     </span><span class="hs-identifier">pokeElemOff</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">ix</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c'</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">div</span><span class="hs-special">`</span><span> </span><span class="hs-number">0x400</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">0xd800</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-155"></span><span>                     </span><span class="hs-identifier">pokeElemOff</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">1</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c'</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">mod</span><span class="hs-special">`</span><span> </span><span class="hs-number">0x400</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">0xdc00</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-156"></span><span>                     </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ix</span><span class="hs-operator">+</span><span class="hs-number">2</span><span class="hs-special">)</span><span>
</span><span id="line-157"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-158"></span><span>    </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">ch</span><span class="hs-cpp">
#else
</span><span id="writeCharBufPtr"><span class="annot"><span class="annottext">writeCharBufPtr :: Ptr Char -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBufPtr"><span class="hs-identifier hs-var hs-var">writeCharBufPtr</span></a></span></span><span> </span><span id="local-6989586621679534377"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534377"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span id="local-6989586621679534376"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534376"><span class="hs-identifier hs-var">ix</span></a></span></span><span> </span><span id="local-6989586621679534375"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534375"><span class="hs-identifier hs-var">ch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; Char -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Char -&gt; Ptr Char
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679534377"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534376"><span class="hs-identifier hs-var">ix</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679534375"><span class="hs-identifier hs-var">ch</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534376"><span class="hs-identifier hs-var">ix</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-163"></span><span class="annot"><a href="GHC.IO.Buffer.html#charSize"><span class="hs-identifier hs-type">charSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span class="hs-identifier">charSize</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">2</span><span class="hs-cpp">
#else
</span><span id="charSize"><span class="annot"><span class="annottext">charSize :: Int
</span><a href="GHC.IO.Buffer.html#charSize"><span class="hs-identifier hs-var hs-var">charSize</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">4</span></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-171"></span><span class="hs-comment">-- Buffers</span><span>
</span><span id="line-172"></span><span>
</span><span id="line-173"></span><span class="hs-comment">-- | A mutable array of bytes that can be passed to foreign functions.</span><span>
</span><span id="line-174"></span><span class="hs-comment">--</span><span>
</span><span id="line-175"></span><span class="hs-comment">-- The buffer is represented by a record, where the record contains</span><span>
</span><span id="line-176"></span><span class="hs-comment">-- the raw buffer and the start/end points of the filled portion.  The</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- buffer contents itself is mutable, but the rest of the record is</span><span>
</span><span id="line-178"></span><span class="hs-comment">-- immutable.  This is a slightly odd mix, but it turns out to be</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- quite practical: by making all the buffer metadata immutable, we</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- can have operations on buffer metadata outside of the IO monad.</span><span>
</span><span id="line-181"></span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- The &quot;live&quot; elements of the buffer are those between the 'bufL' and</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- 'bufR' offsets.  In an empty buffer, 'bufL' is equal to 'bufR', but</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- they might not be zero: for example, the buffer might correspond to</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- a memory-mapped file and in which case 'bufL' will point to the</span><span>
</span><span id="line-186"></span><span class="hs-comment">-- next location to be written, which is not necessarily the beginning</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- of the file.</span><span>
</span><span id="line-188"></span><span class="hs-comment">--</span><span>
</span><span id="line-189"></span><span class="hs-comment">-- On Posix systems the I/O manager has an implicit reliance on doing a file</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- read moving the file pointer.  However on Windows async operations the kernel</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- object representing a file does not use the file pointer offset.  Logically</span><span>
</span><span id="line-192"></span><span class="hs-comment">-- this makes sense since operations can be performed in any arbitrary order.</span><span>
</span><span id="line-193"></span><span class="hs-comment">-- OVERLAPPED operations don't respect the file pointer offset as their</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- intention is to support arbitrary async reads to anywhere at a much lower</span><span>
</span><span id="line-195"></span><span class="hs-comment">-- level.  As such we should explicitly keep track of the file offsets of the</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- target in the buffer.  Any operation to seek should also update this entry.</span><span>
</span><span id="line-197"></span><span class="hs-comment">--</span><span>
</span><span id="line-198"></span><span class="hs-comment">-- In order to keep us sane we try to uphold the invariant that any function</span><span>
</span><span id="line-199"></span><span class="hs-comment">-- being passed a Handle is responsible for updating the handles offset unless</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- other behaviour is documented.</span><span>
</span><span id="line-201"></span><span class="hs-keyword">data</span><span> </span><span id="Buffer"><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span></span><span> </span><span id="local-6989586621679534522"><span class="annot"><a href="#local-6989586621679534522"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-202"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="Buffer"><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-var">Buffer</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-203"></span><span>        </span><span id="bufRaw"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">bufRaw</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534522"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-204"></span><span>        </span><span id="bufState"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var hs-var">bufState</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-205"></span><span>        </span><span id="bufSize"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">bufSize</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span>          </span><span class="hs-comment">-- in elements, not bytes</span><span>
</span><span id="line-206"></span><span>        </span><span id="bufOffset"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var hs-var">bufOffset</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span class="hs-special">,</span><span>       </span><span class="hs-comment">-- start location for next read/write</span><span>
</span><span id="line-207"></span><span>        </span><span id="bufL"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span>          </span><span class="hs-comment">-- offset of first item in the buffer</span><span>
</span><span id="line-208"></span><span>        </span><span id="bufR"><span class="annot"><span class="annottext">forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>           </span><span class="hs-comment">-- offset of last item + 1</span><span>
</span><span id="line-209"></span><span>  </span><span class="hs-special">}</span><span class="hs-cpp">

#if defined(CHARBUF_UTF16)
</span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">CharBuffer</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Buffer</span><span> </span><span class="hs-identifier">Word16</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">type</span><span> </span><span id="CharBuffer"><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-var">CharBuffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-217"></span><span class="hs-keyword">data</span><span> </span><span id="BufferState"><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-var">BufferState</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="ReadBuffer"><span class="annot"><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="WriteBuffer"><span class="annot"><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span></span><span>
</span><span id="line-218"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span id="local-6989586621679534361"><span id="local-6989586621679534363"><span class="annot"><span class="annottext">BufferState -&gt; BufferState -&gt; Bool
(BufferState -&gt; BufferState -&gt; Bool)
-&gt; (BufferState -&gt; BufferState -&gt; Bool) -&gt; Eq BufferState
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: BufferState -&gt; BufferState -&gt; Bool
$c/= :: BufferState -&gt; BufferState -&gt; Bool
== :: BufferState -&gt; BufferState -&gt; Bool
$c== :: BufferState -&gt; BufferState -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></a></span></span></span><span> </span><span class="hs-comment">-- ^ @since 4.2.0.0</span><span>
</span><span id="line-219"></span><span>
</span><span id="line-220"></span><span id="local-6989586621679534512"><span id="local-6989586621679534513"><span class="annot"><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-type">withBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534513"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534513"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534512"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534512"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-221"></span><span id="withBuffer"><span class="annot"><span class="annottext">withBuffer :: forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var hs-var">withBuffer</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534359"><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534359"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679534358"><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679534358"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawBuffer e -&gt; RawBuffer e
forall a b. ForeignPtr a -&gt; ForeignPtr b
</span><a href="GHC.ForeignPtr.html#castForeignPtr"><span class="hs-identifier hs-var">castForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534359"><span class="hs-identifier hs-var">raw</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679534358"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-222"></span><span>
</span><span id="line-223"></span><span id="local-6989586621679534354"><span id="local-6989586621679534355"><span class="annot"><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-type">withRawBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534355"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534355"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534354"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534354"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-224"></span><span id="withRawBuffer"><span class="annot"><span class="annottext">withRawBuffer :: forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var hs-var">withRawBuffer</span></a></span></span><span> </span><span id="local-6989586621679534353"><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534353"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679534352"><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679534352"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawBuffer e -&gt; RawBuffer e
forall a b. ForeignPtr a -&gt; ForeignPtr b
</span><a href="GHC.ForeignPtr.html#castForeignPtr"><span class="hs-identifier hs-var">castForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534353"><span class="hs-identifier hs-var">raw</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679534352"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-225"></span><span>
</span><span id="line-226"></span><span id="local-6989586621679534505"><span class="annot"><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-type">isEmptyBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534505"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-227"></span><span id="isEmptyBuffer"><span class="annot"><span class="annottext">isEmptyBuffer :: forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var hs-var">isEmptyBuffer</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534349"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534349"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534348"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534348"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534349"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534348"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-228"></span><span>
</span><span id="line-229"></span><span id="local-6989586621679534347"><span class="annot"><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier hs-type">isFullBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534347"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-230"></span><span id="isFullBuffer"><span class="annot"><span class="annottext">isFullBuffer :: forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier hs-var hs-var">isFullBuffer</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534345"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534345"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534344"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534344"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534344"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534345"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-231"></span><span>
</span><span id="line-232"></span><span class="hs-comment">-- if a Char buffer does not have room for a surrogate pair, it is &quot;full&quot;</span><span>
</span><span id="line-233"></span><span id="local-6989586621679534343"><span class="annot"><a href="GHC.IO.Buffer.html#isFullCharBuffer"><span class="hs-identifier hs-type">isFullCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534343"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span class="hs-identifier">isFullCharBuffer</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">bufferAvailable</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">2</span><span class="hs-cpp">
#else
</span><span id="isFullCharBuffer"><span class="annot"><span class="annottext">isFullCharBuffer :: forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullCharBuffer"><span class="hs-identifier hs-var hs-var">isFullCharBuffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier hs-var">isFullBuffer</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-240"></span><span id="local-6989586621679534342"><span class="annot"><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-type">isWriteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534342"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-241"></span><span id="isWriteBuffer"><span class="annot"><span class="annottext">isWriteBuffer :: forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-var hs-var">isWriteBuffer</span></a></span></span><span> </span><span id="local-6989586621679534341"><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534341"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Buffer e -&gt; BufferState
forall e. Buffer e -&gt; BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var hs-var">bufState</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534341"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-242"></span><span>                        </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-243"></span><span>                        </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span id="local-6989586621679534340"><span class="annot"><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-type">bufferElems</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534340"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-246"></span><span id="bufferElems"><span class="annot"><span class="annottext">bufferElems :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var hs-var">bufferElems</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534338"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534338"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534337"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534337"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534338"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534337"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-247"></span><span>
</span><span id="line-248"></span><span id="local-6989586621679534336"><span class="annot"><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-type">bufferAvailable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534336"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-249"></span><span id="bufferAvailable"><span class="annot"><span class="annottext">bufferAvailable :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var hs-var">bufferAvailable</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534334"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534334"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534333"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534333"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534333"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534334"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-250"></span><span>
</span><span id="line-251"></span><span id="local-6989586621679534498"><span class="annot"><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier hs-type">bufferRemove</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534498"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534498"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-252"></span><span id="bufferRemove"><span class="annot"><span class="annottext">bufferRemove :: forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier hs-var hs-var">bufferRemove</span></a></span></span><span> </span><span id="local-6989586621679534331"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534331"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span id="local-6989586621679534330"><span class="annot"><span class="annottext">buf :: Buffer e
</span><a href="#local-6989586621679534330"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534329"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534329"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer e -&gt; Buffer e
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534329"><span class="hs-identifier hs-var">r</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534331"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534330"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-253"></span><span>
</span><span id="line-254"></span><span id="local-6989586621679534328"><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-type">bufferAdjustL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534328"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534328"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-255"></span><span id="bufferAdjustL"><span class="annot"><span class="annottext">bufferAdjustL :: forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var hs-var">bufferAdjustL</span></a></span></span><span> </span><span id="local-6989586621679534326"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534326"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679534325"><span class="annot"><span class="annottext">buf :: Buffer e
</span><a href="#local-6989586621679534325"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534324"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534324"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-256"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534326"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534324"><span class="hs-identifier hs-var">w</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534325"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-257"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534325"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534326"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534324"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-258"></span><span>
</span><span id="line-259"></span><span id="local-6989586621679534323"><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdd"><span class="hs-identifier hs-type">bufferAdd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534323"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534323"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-260"></span><span id="bufferAdd"><span class="annot"><span class="annottext">bufferAdd :: forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdd"><span class="hs-identifier hs-var hs-var">bufferAdd</span></a></span></span><span> </span><span id="local-6989586621679534321"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534321"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span id="local-6989586621679534320"><span class="annot"><span class="annottext">buf :: Buffer e
</span><a href="#local-6989586621679534320"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534319"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534319"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534320"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534319"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534321"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-261"></span><span>
</span><span id="line-262"></span><span id="local-6989586621679534318"><span class="annot"><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-type">bufferOffset</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534318"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span></span><span>
</span><span id="line-263"></span><span id="bufferOffset"><span class="annot"><span class="annottext">bufferOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var hs-var">bufferOffset</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534317"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534317"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534317"><span class="hs-identifier hs-var">off</span></a></span><span>
</span><span id="line-264"></span><span>
</span><span id="line-265"></span><span id="local-6989586621679534493"><span class="annot"><a href="GHC.IO.Buffer.html#bufferAdjustOffset"><span class="hs-identifier hs-type">bufferAdjustOffset</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534493"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534493"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-266"></span><span id="bufferAdjustOffset"><span class="annot"><span class="annottext">bufferAdjustOffset :: forall e. Word64 -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustOffset"><span class="hs-identifier hs-var hs-var">bufferAdjustOffset</span></a></span></span><span> </span><span id="local-6989586621679534316"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534316"><span class="hs-identifier hs-var">offs</span></a></span></span><span> </span><span id="local-6989586621679534315"><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534315"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534315"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534316"><span class="hs-identifier hs-var">offs</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-267"></span><span>
</span><span id="line-268"></span><span class="hs-comment">-- The adjustment to the offset can be 32bit int on 32 platforms.</span><span>
</span><span id="line-269"></span><span class="hs-comment">-- This is fine, we only use this after reading into/writing from</span><span>
</span><span id="line-270"></span><span class="hs-comment">-- the buffer so we will never overflow here.</span><span>
</span><span id="line-271"></span><span id="local-6989586621679534314"><span class="annot"><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-type">bufferAddOffset</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534314"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534314"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-272"></span><span id="bufferAddOffset"><span class="annot"><span class="annottext">bufferAddOffset :: forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var hs-var">bufferAddOffset</span></a></span></span><span> </span><span id="local-6989586621679534309"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534309"><span class="hs-identifier hs-var">offs</span></a></span></span><span> </span><span id="local-6989586621679534308"><span class="annot"><span class="annottext">buf :: Buffer e
</span><a href="#local-6989586621679534308"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534307"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534307"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-273"></span><span>  </span><span class="annot"><span class="annottext">Buffer e
</span><a href="#local-6989586621679534308"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679534307"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Word64 -&gt; Word64 -&gt; Word64
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Word64
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534309"><span class="hs-identifier hs-var">offs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span id="local-6989586621679534488"><span class="annot"><a href="GHC.IO.Buffer.html#emptyBuffer"><span class="hs-identifier hs-type">emptyBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534488"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534488"><span class="hs-identifier hs-type">e</span></a></span></span><span>
</span><span id="line-276"></span><span id="emptyBuffer"><span class="annot"><span class="annottext">emptyBuffer :: forall e. RawBuffer e -&gt; Int -&gt; BufferState -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#emptyBuffer"><span class="hs-identifier hs-var hs-var">emptyBuffer</span></a></span></span><span> </span><span id="local-6989586621679534305"><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534305"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679534304"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534304"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span id="local-6989586621679534303"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534303"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-277"></span><span>  </span><span class="annot"><span class="annottext">Buffer :: forall e.
RawBuffer e
-&gt; BufferState -&gt; Int -&gt; Word64 -&gt; Int -&gt; Int -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679534305"><span class="hs-identifier hs-var">raw</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534303"><span class="hs-identifier hs-var">state</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534304"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-278"></span><span>
</span><span id="line-279"></span><span class="annot"><a href="GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier hs-type">newByteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-280"></span><span id="newByteBuffer"><span class="annot"><span class="annottext">newByteBuffer :: Int -&gt; BufferState -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier hs-var hs-var">newByteBuffer</span></a></span></span><span> </span><span id="local-6989586621679534302"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534302"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679534301"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534301"><span class="hs-identifier hs-var">st</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer Word8)
forall e. Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer e)
</span><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534302"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534302"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534301"><span class="hs-identifier hs-var">st</span></a></span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span class="annot"><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-type">newCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-283"></span><span id="newCharBuffer"><span class="annot"><span class="annottext">newCharBuffer :: Int -&gt; BufferState -&gt; IO CharBuffer
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var hs-var">newCharBuffer</span></a></span></span><span> </span><span id="local-6989586621679534300"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534300"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679534299"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534299"><span class="hs-identifier hs-var">st</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BufferState -&gt; IO CharBuffer
forall e. Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer e)
</span><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534300"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Buffer.html#charSize"><span class="hs-identifier hs-var">charSize</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534300"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534299"><span class="hs-identifier hs-var">st</span></a></span><span>
</span><span id="line-284"></span><span>
</span><span id="line-285"></span><span id="local-6989586621679534486"><span class="annot"><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-type">newBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534486"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-286"></span><span id="newBuffer"><span class="annot"><span class="annottext">newBuffer :: forall e. Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer e)
</span><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-var hs-var">newBuffer</span></a></span></span><span> </span><span id="local-6989586621679534295"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534295"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span id="local-6989586621679534294"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534294"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span id="local-6989586621679534293"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534293"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-287"></span><span>  </span><span id="local-6989586621679534292"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679534292"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (ForeignPtr e)
forall a. Int -&gt; IO (ForeignPtr a)
</span><a href="GHC.ForeignPtr.html#mallocForeignPtrBytes"><span class="hs-identifier hs-var">mallocForeignPtrBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534295"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-288"></span><span>  </span><span class="annot"><span class="annottext">Buffer e -&gt; IO (Buffer e)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignPtr e -&gt; Int -&gt; BufferState -&gt; Buffer e
forall e. RawBuffer e -&gt; Int -&gt; BufferState -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#emptyBuffer"><span class="hs-identifier hs-var">emptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679534292"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534294"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534293"><span class="hs-identifier hs-var">state</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-289"></span><span>
</span><span id="line-290"></span><span class="hs-comment">-- | slides the contents of the buffer to the beginning</span><span>
</span><span id="line-291"></span><span class="annot"><a href="GHC.IO.Buffer.html#slideContents"><span class="hs-identifier hs-type">slideContents</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-292"></span><span id="slideContents"><span class="annot"><span class="annottext">slideContents :: Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Buffer.html#slideContents"><span class="hs-identifier hs-var hs-var">slideContents</span></a></span></span><span> </span><span id="local-6989586621679534290"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679534290"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534289"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534289"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534288"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534288"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534287"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534287"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-293"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679534285"><span class="annot"><span class="annottext">elems :: Int
</span><a href="#local-6989586621679534285"><span class="hs-identifier hs-var hs-var">elems</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534288"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534289"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-294"></span><span>  </span><span class="annot"><span class="annottext">RawBuffer Word8 -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var">withRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679534287"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679534284"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534284"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-295"></span><span>      </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; CSize -&gt; IO (Ptr Word8)
forall a. Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr a)
</span><a href="GHC.IO.Buffer.html#memmove"><span class="hs-identifier hs-var">memmove</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534284"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679534284"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534289"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534285"><span class="hs-identifier hs-var">elems</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-296"></span><span>         </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-297"></span><span>  </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679534290"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534285"><span class="hs-identifier hs-var">elems</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span id="local-6989586621679534482"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;memmove&quot;</span></span><span>
</span><span id="line-300"></span><span>   </span><span id="memmove"><span class="annot"><a href="GHC.IO.Buffer.html#memmove"><span class="hs-identifier hs-var">memmove</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534482"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534482"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534482"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-301"></span><span>
</span><span id="line-302"></span><span id="local-6989586621679534479"><span class="annot"><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-type">summaryBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534479"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span></span><span>
</span><span id="line-303"></span><span id="summaryBuffer"><span class="annot"><span class="annottext">summaryBuffer :: forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var hs-var">summaryBuffer</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679534273"><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span></span><span>  </span><span class="hs-comment">-- Strict =&gt; slightly better code</span><span>
</span><span id="line-304"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String
</span><a href="#local-6989586621679534272"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawBuffer a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">(RawBuffer a -&gt; String) -&gt; RawBuffer a -&gt; String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a -&gt; RawBuffer a
forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;@buf&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer a -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-305"></span><span>   </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer a -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;-&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer a -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;)&quot;</span></span><span>
</span><span id="line-306"></span><span>   </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; (&gt;=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer a -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var hs-var">bufOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534273"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;)&quot;</span></span><span>
</span><span id="line-307"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span class="annot"><a href="#local-6989586621679534272"><span class="hs-identifier hs-type">ppr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-308"></span><span>        </span><span id="local-6989586621679534272"><span class="annot"><span class="annottext">ppr :: String -&gt; String
</span><a href="#local-6989586621679534272"><span class="hs-identifier hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'0'</span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'x'</span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679534270"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534270"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679534267"><span class="annot"><span class="annottext">p :: String
</span><a href="#local-6989586621679534267"><span class="hs-identifier hs-var hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="GHC.List.html#dropWhile"><span class="hs-identifier hs-var">dropWhile</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'0'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534270"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-309"></span><span>                           </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.List.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534267"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;0x0&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'0'</span></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'x'</span></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534267"><span class="hs-identifier hs-var">p</span></a></span><span>
</span><span id="line-310"></span><span>        </span><span class="annot"><a href="#local-6989586621679534272"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span id="local-6989586621679534264"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534264"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679534264"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-311"></span><span>
</span><span id="line-312"></span><span class="hs-comment">-- Note [INVARIANTS on Buffers]</span><span>
</span><span id="line-313"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-314"></span><span class="hs-comment">--   * r &lt;= w</span><span>
</span><span id="line-315"></span><span class="hs-comment">--   * if r == w, and the buffer is for reading, then r == 0 &amp;&amp; w == 0</span><span>
</span><span id="line-316"></span><span class="hs-comment">--   * a write buffer is never full.  If an operation</span><span>
</span><span id="line-317"></span><span class="hs-comment">--     fills up the buffer, it will always flush it before</span><span>
</span><span id="line-318"></span><span class="hs-comment">--     returning.</span><span>
</span><span id="line-319"></span><span class="hs-comment">--   * a read buffer may be full as a result of hLookAhead.  In normal</span><span>
</span><span id="line-320"></span><span class="hs-comment">--     operation, a read buffer always has at least one character of space.</span><span>
</span><span id="line-321"></span><span>
</span><span id="line-322"></span><span id="local-6989586621679534471"><span class="annot"><a href="GHC.IO.Buffer.html#checkBuffer"><span class="hs-identifier hs-type">checkBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534471"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-323"></span><span id="checkBuffer"><span class="annot"><span class="annottext">checkBuffer :: forall a. Buffer a -&gt; IO ()
</span><a href="GHC.IO.Buffer.html#checkBuffer"><span class="hs-identifier hs-var hs-var">checkBuffer</span></a></span></span><span> </span><span id="local-6989586621679534250"><span class="annot"><span class="annottext">buf :: Buffer a
</span><a href="#local-6989586621679534250"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: forall e. Buffer e -&gt; BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679534249"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534249"><span class="hs-identifier hs-var">state</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534248"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534248"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534247"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679534246"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534246"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-324"></span><span>     </span><span class="annot"><span class="annottext">Buffer a -&gt; Bool -&gt; IO ()
forall a. Buffer a -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Buffer.html#check"><span class="hs-identifier hs-var">check</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534250"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-325"></span><span>        </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534246"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-326"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534248"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-327"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534246"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-328"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534248"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534249"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState -&gt; BufferState -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534248"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-329"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679534249"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState -&gt; BufferState -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534247"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679534246"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- write buffer is never full</span><span>
</span><span id="line-330"></span><span>      </span><span class="hs-special">)</span><span>
</span><span id="line-331"></span><span>
</span><span id="line-332"></span><span id="local-6989586621679534469"><span class="annot"><a href="GHC.IO.Buffer.html#check"><span class="hs-identifier hs-type">check</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679534469"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-333"></span><span id="check"><span class="annot"><span class="annottext">check :: forall a. Buffer a -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Buffer.html#check"><span class="hs-identifier hs-var hs-var">check</span></a></span></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><span class="hs-identifier">_</span></span><span>   </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-334"></span><span class="annot"><a href="GHC.IO.Buffer.html#check"><span class="hs-identifier hs-var">check</span></a></span><span> </span><span id="local-6989586621679534237"><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534237"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;buffer invariant violation: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer a
</span><a href="#local-6989586621679534237"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-335"></span><span>
</span><span id="line-336"></span></pre></body></html>